var openContainer = null;
var openMenu = null;
var timer = null;

function startTimeout ( hideTimeout ) {
	timer = setTimeout ( "hideMenus ( )", hideTimeout );	
}

function hideMenus ( ) {
	resetTimeout ( );
	if ( openContainer ) {
		var c = document.getElementById ( openContainer );
		c.style.visibility = "inherit";
		openContainer = null;
	}
	if (  openMenu  ) {
		for ( var i = 0; i < openMenu.length ; i++ ) {
			var m = document.getElementById ( openMenu[i] );
			m.style.visibility = "hidden";			
		}
		openMenu = null;
	}
}

function hideSubMenu ( menuName ) {
	if (  openMenu  ) {
		var h = false;
		var c = 0;
		for ( var i = 0; i < openMenu.length ; i++ ) {
			if (  h  ) {
				alert ( openMenu[i] );
				var m = document.getElementById ( openMenu[i] );
				m.style.visibility = "hidden";
			} else if (  openMenu[i] == menuName  ) {
				h = true;
			} else {
				c++;
			}
		}
		openMenu.length = c+1;
	}
}

function overItem ( menuName, subMenuSuffix ) {
	resetTimeout ( );
	hideSubMenu ( menuName );
	if (  subMenuSuffix  ) {
		var subMenuName = "" + menuName + "_" + subMenuSuffix;
		showSubMenu ( subMenuName );
	}
}

function showSubMenu ( subMenuName ) {
	resetTimeout ( );
	var e = document.getElementById ( subMenuName );
	e.style.visibility = "visible";
	if (  !openMenu  ) {
		openMenu = new Array;
	}
	openMenu[openMenu.length] = "" + subMenuName;
}

function resetTimeout ( ) {
	if  ( timer ) clearTimeout ( timer );
	timer = null;
}

function showMenu ( containName, menuName, xOffset, yOffset, triggerName  ) {
	hideMenus ( );
	resetTimeout ( );
	showContainer ( containName, xOffset, yOffset, triggerName );
	showSubMenu ( menuName );
}

function showContainer ( containName, x, y, triggerName ) {	
	var c = document.getElementById ( containName );
	var s = c.style;
	s.visibility = "visible";
	//s.visibility = "inherit";
	s.left = x + "px";
	s.top = y + "px";
	openContainer = "" + containName;
}